package com.zx.web.servelt;

import com.zx.bean.GoodsType;
import com.zx.web.service.AdminGoodsTypeService;
import com.zx.web.service.impl.AdminGoodsTypeServiceImpl;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @author 章鑫
 * @version V1.0
 * @Project 2022-09-05
 * @Package com.zx.web.servelt
 * @Description:
 * @Date 2022/9/16 13:50
 */
@WebServlet("/admingoodstypeservlet")
public class AdminGoodsTypeServlet extends BaseServlet{

    AdminGoodsTypeService adminGoodsTypeService = new AdminGoodsTypeServiceImpl();

    /**
     * 查找种类
     * @param req
     * @param resp
     * @return
     */
    public String getGoodsType(HttpServletRequest req, HttpServletResponse resp){
        String flag = req.getParameter("flag");
        //查找种类
        List<GoodsType> goodsTypeList = adminGoodsTypeService.findGoodType();
        req.setAttribute("goodsTypeList",goodsTypeList);

        if("addGoods".equalsIgnoreCase(flag)){
            return "forward:/admin/addGoods.jsp";
        }

        if("add".equalsIgnoreCase(flag)){
            return "forward:/admin/addGoodsType.jsp";
        }
        return "forward:/admin/showGoodsType.jsp";
    }


    public String addGoodsType(HttpServletRequest req, HttpServletResponse resp){

        int goodsParent = Integer.parseInt(req.getParameter("goodsParent"));
        String typename = req.getParameter("typename");

        adminGoodsTypeService.addGoodsType(goodsParent,typename);

        return "redirect:/admingoodstypeservlet?method=getGoodsType&flag=show";
    }



}
